//改文件用于创建vuex中最为核心的store

//引入vuex
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

//求和相关配置
const countOptions = {
    actions: {
        jiaOdd(context,value) {
            console.log('actions中的jia被调用了',context,value) 
            context.commit('jia',value)
         },
         jiaWait(context, value) {
             setTimeout(()=>{
                 console.log('actions中的jian被调用了', context, value)
                 context.commit('jian',value)
             },3000) 
         }
    },
    mutations: {
        jia(state,value) {
            console.log('mutations中的jia被调用了', state, value)
            state.sum +=value
        },
        jian(state, value) {
            console.log('mutations中的jian被调用了', state, value)
            state.sum -= value
        },
    },
    state: {
        sum: 0,
        school: '尚硅谷',
        subject: 'vue',
    },
    getters: {
        bigSum(state) {
            return state.sum*10
        }
    }
}

//人员管理相关配置
const personOptions = {
    actions: {},
    mutations: {
        ADD_PERSONS(state, value) {
            console.log('mutations中的ADD_PERSONS被调用了', state, value)
            state.personList.unshift(value)
        }
    },
    state: {
        personList:[{name:'张三'}]
    },
    getters: {}
}

//准备actions--用于响应组件中的动作
const actions = {
    
}
//准备mutations--用于操作数据(state)
const mutations = {
    
    
}
//准备state--用于存储数据
const state = {
    
}
//准备getters--用于将state中的数据进行加工
const getters = {
    
}

//创建并暴露store
export default new Vuex.Store({
    modules: {
        countAbout: countOptions,
        personAbout: personOptions,
   }
})